package org.epidroid.epidroid.androsoul.ui.contactlist;

import java.util.Comparator;

import org.epidroid.epidroid.androsoul.engine.contacts.NetsoulContact;

public class ContactComparatorOnLineTop implements Comparator<NetsoulContact> {

	@Override
	public int compare(NetsoulContact c1, NetsoulContact c2) {

		if (!c1.getLocations().isEmpty() && !c2.getLocations().isEmpty()) {
			// They are both connected

			if (c1.getState().equals("actif")
					&& (!c2.getState().equals("actif")))
				return -1;
			if (!c1.getState().equals("actif")
					&& (c2.getState().equals("actif")))
				return 1;

			return c1.getName().compareTo(c2.getName());
		}

		if (!c1.getLocations().isEmpty())
			return -1;
		if (!c2.getLocations().isEmpty())
			return 1;

		return c1.getName().compareTo(c2.getName());
	}
}
